package com.zr.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.BaseDao;
import com.zr.dao.GoodTypeDao;
import com.zr.datamodel.GoodTypeDM;
import com.zr.dto.GoodTypeDto;
import com.zr.dto.OrderDto;
import com.zr.service.GoodTypeService;

import net.sf.json.JSONObject;
@Service("goodTypeService")
public class GoodTypeServiceImpl implements GoodTypeService{
	@Resource
	private BaseDao<GoodTypeDM> baseDao;
	@Resource
	private GoodTypeDao goodTypeDao;
	@Override
	public JSONObject findGoodTypeName(int page, int rows) {
		// TODO Auto-generated method stub
		JSONObject obj=new JSONObject();
		try {
			obj.put("total",goodTypeDao.findGoodTypeCount());
			//obj.put("rows", goodTypeDao.findGoodTypeName(page, rows));
			List<GoodTypeDM> goodTypes=goodTypeDao.findGoodTypeName(page, rows);
			List<GoodTypeDto> list = new ArrayList<>();
			for (GoodTypeDM goodType : goodTypes) {
				GoodTypeDto g=new GoodTypeDto();
				g.setId(goodType.getId());
				g.setName(goodType.getName());
				g.setRemark(goodType.getRemark());
				list.add(g);
			}
			obj.put("rows", list);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		return obj;
	}
	@Override
	public void insertGoodType(GoodTypeDM goodType){
		// TODO Auto-generated method stub
		goodTypeDao.insertGoodType(goodType);
	}
	@Override
	public void delGoodType(String[] ids) {
		// TODO Auto-generated method stub
		for (int i = 0; i < ids.length; i++) {
			goodTypeDao.delGoodType(Integer.valueOf(ids[i]));
		}
	}
	@Override
	public void updateGoodType(GoodTypeDM goodType) {
		// TODO Auto-generated method stub
		goodTypeDao.updateGoodType(goodType);
	}
	

}
